package com.cnoc.base.executor;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class QueueExecuter {

	   private ThreadPoolExecutor executor = null;
	   private static final int poolmax = 250;
	   public QueueExecuter(){}
	   
	   public void init(){
		   executor  = new ThreadPoolExecutor(10,poolmax,5,TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>());
	   }
	   
	   public void execute(Runnable task){
		   executor.execute(task);
		   System.out.println(getMessage());
	   }
	   
	   public void remove(Runnable task){
		   executor.remove(task);
		   System.out.println(getMessage());
	   }
	   
	   public String getMessage(){
		   int activeCount = executor.getActiveCount();
		   long lifetime = executor.getKeepAliveTime(TimeUnit.SECONDS);
		   
		   return "queue thread info:activecount-"+activeCount+",lifetime-"+lifetime;
	   }
}
